﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform.Dc
{
    /// <summary>
    /// 使用频次字典
    /// </summary>
    public class RxUsedFrquService : CrudAppService<RxUsedFrqu, RxUsedFrquDto, Guid, UsedFrquDictInput, RxUsedFrquCreateDto, RxUsedFrquUpdateDto>
    {
        private IRepository<RxUsedFrqu, Guid> _usedFrquDictRepository;

        public RxUsedFrquService(IRepository<RxUsedFrqu, Guid> usedFrquDictRepository) : base(usedFrquDictRepository)
        {
            _usedFrquDictRepository = usedFrquDictRepository;
        }

        /// <summary>
        /// 获取使用频次字典
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<RxUsedFrquDto>> GetListAsync(UsedFrquDictInput input)
        {
            var iQuery = await _usedFrquDictRepository.GetQueryableAsync();

            if (input.SkipCount == 0)
            {
                var itemsDto = ObjectMapper.Map<List<RxUsedFrqu>, List<RxUsedFrquDto>>(iQuery.ToList());

                return new PagedResultDto<RxUsedFrquDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.SkipCount, input.MaxResultCount);
                var itemsDto = ObjectMapper.Map<List<RxUsedFrqu>, List<RxUsedFrquDto>>(items.ToList());

                return new PagedResultDto<RxUsedFrquDto>(totalCount, itemsDto);
            }
        }
    }
}
